<template>
  <div class="containner">
    <el-upload
      :class="hide ? 'isHide' : ''"
      class="avatar-uploader"
      action="https://jsonplaceholder.typicode.com/posts/"
      :show-file-list="false"
      :on-success="handleAvatarSuccess"
      :before-upload="beforeAvatarUpload"
    >
      <img v-if="imageUrl" :src="imageUrl" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      <template #tip>
        <div class="el-upload__tip" :style="hide ? 'display:none' : ''">
          只能上传jpg/png文件，且不超过500kb
        </div>
      </template>
    </el-upload>
  </div>
</template>

<script>
export default {
  props: {
    imageUrl: {
      type: String,
      default: "",
    },
    hide: {
      type: Boolean,
      default: false,
    },
  },
  components: {},

  data() {
    return {};
  },

  created() {},

  mounted() {},

  methods: {
    // 上传成功之前
    beforeAvatarUpload() {},
    // 上传成功
    handleAvatarSuccess(res, file) {},
  },
};
</script>
<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader {
  &.isHide {
    text-align: center;
  }
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
  border: 1px dashed #d9d9d9;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
